package com.estate.business.impl;

import java.util.Date;
import java.util.List;

import com.estate.business.ThingsTodoService;
import com.estate.dao.ThingsTodoDao;
import com.estate.utils.AnnouncementUtil;
import com.estate.vo.Vo;
import com.estate.vo.impl.AnnouncementVo;
import com.estate.vo.impl.ThingsTodoVo;
import com.estate.vo.impl.UserInfoVo;

public class ThingsTodoServiceImpl implements ThingsTodoService {
	
	private ThingsTodoDao thingsDao;

	public boolean addThingsTodo(ThingsTodoVo thingsVo) {
		boolean result = false;
		result = this.getThingsDao().addVo(thingsVo);
		return result;
	}

	
	public boolean deleteThingsVo(ThingsTodoVo thingsVo) {
		boolean result = false;
		result = this.getThingsDao().deleteVo(thingsVo);
		return result;
	}

	public List<Vo> getAllThingsVo(UserInfoVo userInfo) {
		List<Vo> thingsList = this.getThingsDao().findAllMyThings(userInfo);
		return thingsList;
	}

	public Vo getThingsVo(Integer pk) {
		Vo vo = this.getThingsDao().findByPK(pk);
		return vo;
	}

	public boolean updateThingsVo(ThingsTodoVo thingsVo) {
		boolean result = false;
		ThingsTodoVo old = (ThingsTodoVo) this.getThingsDao().findByPK(thingsVo.getId());
		thingsVo.setPostDate(old.getPostDate());
		result = this.getThingsDao().updateVo(thingsVo);
		return result;
	}
	public ThingsTodoDao getThingsDao() {
		return thingsDao;
	}

	public void setThingsDao(ThingsTodoDao thingsDao) {
		this.thingsDao = thingsDao;
	}


	public boolean deleteMultiThings(String delStr) {
		if(delStr!= null && !"".equals(delStr) && !",".equals(delStr)){
			String[] delArray = delStr.split(",");
			ThingsTodoVo things = null;
			for(int i = 0;i<delArray.length;i++){
				things = new ThingsTodoVo();
				things.setId(Integer.parseInt(delArray[i]));
				this.deleteThingsVo(things);
			}
		}
		return true;
	}


	public boolean updatePost(int id) {
		ThingsTodoVo old = (ThingsTodoVo) this.getThingsDao().findByPK(id);
		old.setState(AnnouncementUtil.getAnnouncementString(2));
		old.setPostDate(new Date());
		boolean result = this.getThingsDao().updateVo(old);
		return result;
	}

}
